package com.qf.mapper;

import com.qf.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    //根据ID查询
    @Select("SELECT " +
            "order_id, " +
            "product_name, " +
            "quantity, " +
            "price, " +
            "create_time, " +
            "user_id " +
            "FROM tb_order " +
            "WHERE user_id = #{userId}")
    List<Order> selectOrdersByUserId(Integer userId);
    //添加
    @Insert("insert into tb_order(product_name, quantity, price, create_time, user_id) " +
            "values(#{productName}, #{quantity}, #{price}, #{createTime}, #{userId})")
    void addOrder(Order order);
    //单独删除
    @Delete("delete from tb_order where order_id=#{orderId} ")
    void  deleteOrder(Integer orderId);
    //批量删除
    @Delete("<script>" +
            "delete from tb_order where order_id in " +
            "<foreach collection='orderids' item='id' open='(' separator=',' close=')'>" +
            " #{id} " +
            "</foreach>" +
            "</script>")
    void batchDelete(@Param("orderids") List<Integer> orids);
    //模糊查询
    @Select("select * from tb_order where user_id = #{userId} and product_name like concat('%', #{productName}, '%')")
    List<Order> findByOrdernameLike(@Param("userId") Integer userId, @Param("productName") String productName);
}
